<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2019/11/24
 * Time: 22:09
 */
namespace app\admin\model;

use think\Model;
use think\Request;

class Emplist extends Model
{
    protected $table = 'tb_emp';
//    protected $name = 'tb_emp';

    public function getIconAttr($value)
    {
        return empty($value) ? '': fixed_url() . 'uploads/' . $value;
    }

    public function dept()
    {
        return $this->belongsTo('Dept', 'Edeptno');
    }

    public function addEmp($data)
    {
        $this->save($data);
    }

    public function getList($param = [])
    {
        $params = array_merge([
            'Eno' => 0,
            'Ename' => '',
            'search' => ''
        ], $param);
        $filters = [];
        //精确查找
        $params['Eno'] > 0 && $filters['Eno'] = $params['Eno'];
        !empty($params['Ename']) && $filters['Ename'] = $params['Ename'];
        //搜索
        !empty($params['search']) && $this->where('Eno|Ename', 'like', "%$params[search]%");

        $this->where($filters);
        return $this->with('dept')
            ->paginate(10, false, [
                'query' => Request::instance()->request()
            ]);
    }
}
